package com.jic.market.mapper;

import com.jic.market.entity.PatchGrouponThemeMpEntity;
import com.jic.market.entity.PatchGrouponThemeMpQuery;
import com.jic.market.model.MpQueryUniqueCondition;
import com.jic.market.orm.BaseMapper;
import com.jic.market.entity.PatchGrouponMpEntity;
import com.jic.market.orm.Pagination;
import com.jic.market.request.rest.groupon.QueryGroupProductListRequest;
import com.jic.market.response.rest.groupon.QueryGroupProductListResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PatchGrouponMpEntityMapper extends BaseMapper<PatchGrouponMpEntity> {

    PatchGrouponMpEntity getByPromotionIdAndMpId(@Param("promotionId") Long promotionId, @Param("mpId") Long mpId);

    /**
     * @param condition
     * @return
     */
    PatchGrouponMpEntity getMpQueryUnique(MpQueryUniqueCondition condition);

    /**
     * 根据 促销id 和 商品id 删除
     *
     * @param promotionId
     * @param mpId
     * @return
     */
    Integer deleteEntityByPromotionIdAndMpId(
            @Param("promotionId") Long promotionId, @Param("mpId") Long mpId);

    /**
     * 根据 促销id删除
     *
     * @param promotionId
     * @return
     */
    Integer deleteEntityByPromotionId(
            @Param("promotionId") Long promotionId);
    /**
     * 通过 promotionId  和storeIds查询列表
     *
     * @param promotionId
     * @param storeIds
     * @return
     */
    List<PatchGrouponMpEntity> queryEntityListByPromotionIdAndStoreIds(
            @Param("promotionId") Long promotionId, @Param("storeIds") List<Long> storeIds);

    /**
     * 根据 促销id 和 店铺ids  批量删除商品
     *
     * @param promotionId
     * @param storeIds
     * @return
     */
    Integer deleteEntityListByPromotionIdAndStoreIdsBatch(
            @Param("promotionId") Long promotionId, @Param("storeIds") List<Long> storeIds);

    /**
     * 批量保存商品信息
     *
     * @param list
     * @return
     */
    Long batchSaveMp(@Param("list") List<PatchGrouponMpEntity> list);

    @Select("select a.mp_id from patch_groupon_mp a where FIND_IN_SET(a.id,#{ids})")
    List<Long> queryEntityListByIds(@Param("ids") String ids);

    @Update("UPDATE patch_groupon_mp SET mutex_flag = 0 WHERE FIND_IN_SET(id,#{ids})")
    void updateMutexByIds(@Param("ids") String ids);

    @Update("UPDATE patch_groupon_mp SET mutex_flag = 0 WHERE promotion_id = #{promotionId} and FIND_IN_SET(mp_id,#{mpIds})")
    void updateNoMutexListByPromotionIdAndMpId(@Param("promotionId") Long promotionId, @Param("mpIds") String ids);
//    /**
//     * 查询出此商品参与的所有活动id
//     * @param thirdProductCode
//     * @return
//     */
//    List<String> queryAllPromotionIdByThirdProductCode(String thirdProductCode);


    List<PatchGrouponThemeMpEntity> getIngThemeMps(@Param("po") PatchGrouponThemeMpQuery param, @Param("page") Pagination pagination);

    Integer countIngThemeMps(@Param("po") PatchGrouponThemeMpQuery param);

    List<PatchGrouponMpEntity> findMutexOfPage(@Param("po") PatchGrouponMpEntity productCondition, @Param("page") Pagination pagination);

    Integer countMutexOfPage(@Param("po") PatchGrouponMpEntity productCondition);

    Integer getSkuCount(@Param("promotionId") Long promotionId, @Param("mpId") Long mpId);

    List<QueryGroupProductListResponse> queryProcessingProductPage(QueryGroupProductListRequest request);

    Long queryProcessingProductCount();
}